﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_TraPurchaseZero : System.Web.UI.Page, HZ.MBSM.BLL.TraDes
{
    string _strProjectId, Accountid_PS;
    string BuyPlanId = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
        {
          //  _strProjectId = SysFun.ToTrim(Request.QueryString["ProjectId"]);    07/09/11 马
            
           // if (_strProjectId != "")
           // {



                //<!--删除
                if (Request.Form["submitDel"] == "删除" && Request.Form["chk"] != null)
                {
                    string _strBuyPlanGoodsId = SysFun.ToTrim(Request.Form["chk"]);

                    Db db = new Db();
                    if (_strBuyPlanGoodsId != "")
                    {
                        string _strSql = "delete from BuyPlanGoods where BuyPlanGoodsId in (" + _strBuyPlanGoodsId + ")";
                        db.Command(_strSql);
                    }

                    db.Close();


                }
                //删除-->

                showGridView();
         //   }
            //else
            // {
            //     Response.Write("<script>window.close();</script>");
            // }
            //如果采购单号或项目号为空，那么关闭本页面-->
        }
    }


    public void showGridView()
    {
        int i = 0;
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        string _strWhere = fctConditions();
        //dbPage.Table = "BuyGoodsView ";                                               //要查询的表明  07/09/11 马
        dbPage.Table = "BuyGoodsView_200708 ";                                               //要查询的表明
        dbPage.Key = "BuyPlanGoodsId";                                               //表的主键    
        dbPage.Where = _strWhere;                                          //查询条件    
        dbPage.SelectField = "StartTime,EndTime,BuildTime,UserCode,HospitalName,BuyPlanGoodsId,InflowNum,GoodsNum,BuyPlanId,SupplyGoodsId,GoodsId,ProductCode,ProductName,MedicineModel,Outlookc,BuyGoodsView_200708.ProjectId,Factor,CompanyName_SC,UserCode_SC,CompanyName_TB,TradePrice,Case DealStatus When '0' Then '未确认' else  '确认送货'  END AS DealStatus,GoodsName,IsNull(Unit,'')+'/'+IsNull(PackUnit,'') As Pack1,QualityLevels,Case GoodsState When '0' Then '原中标' WHEN '1' Then '备案采购商品' WHEN '2' then '不限价不竞价商品' END AS GoodsState";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 30;                                                    //没有显示记录条数   
        dbPage.OrderBy = "StartTime ,ProductName,MedicineModel,Outlookc,CompanyName_SC,BuyPlanGoodsId";//排序字段
        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();
        strHtml.Append("<table width='98%' border='0' align='center' cellpadding='2' cellspacing='1' class='table_table'>");
        strHtml.Append("<tr>");
        strHtml.Append("<td  class='table_title' >采购单号</td>");
        strHtml.Append("<td  class='table_title' width='8%'>商品流水号</td>");
        strHtml.Append("<td  class='table_title' width='8%'>通用名</td>");
        strHtml.Append("<td  class='table_title' width='5%'>商品名</td>");
        strHtml.Append("<td  class='table_title' nowrap>剂型</td>");
        strHtml.Append("<td  class='table_title' nowrap>规格</td>");
        strHtml.Append("<td  class='table_title' width='5%'>转换系数</td>");
        strHtml.Append("<td  class='table_title' >包装规格</td>");
        strHtml.Append("<td  class='table_title'>质量层次</td>");
        strHtml.Append("<td  class='table_title'>交易价</td>");
        strHtml.Append("<td  class='table_title'>采购量</td>");
        strHtml.Append("<td  class='table_title'>采购医院</td>");
        strHtml.Append("<td  class='table_title' width='9%'>生产企业</td>");
        strHtml.Append("<td  class='table_title' >生产企业注册号</td>");

        strHtml.Append("<td  class='table_title'>处理状态</td>");
        strHtml.Append("<td  class='table_title' width='10%'>详情</td>");
        strHtml.Append("<td  class='table_title' nowrap>选择</td>");
        strHtml.Append("</tr>");
        System.Data.IDataReader dr = dbPage.ExecuteReader();

        while (dr.Read())
        {
            if (i == 0)
            {
                strHtml.Append("<tr class='table_td'>");
                i++;
            }
            else
            {
                strHtml.Append("<tr class='table_td2'>");
                i--;
            }
            strHtml.Append("<td>" + dr["BuyPlanId"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["GoodsId"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["ProductName"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["GoodsName"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Medicinemodel"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Outlookc"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Factor"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Pack1"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["QualityLevels"].ToString() + "</td>");
            strHtml.Append("<td>" + SysFun.OutNum(dr["TradePrice"].ToString(), 2) + "</td>");
            strHtml.Append("<td>" + SysFun.ToTrim(dr["GoodsNum"]) + "</td>");
            strHtml.Append("<td>" + SysFun.ToTrim(dr["HospitalName"]) + "</td>");
            strHtml.Append("<td>" + dr["CompanyName_SC"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["UserCode_SC"].ToString() + "</td>");

            strHtml.Append("<td>" + dr["DealStatus"].ToString() + "</td>");
            strHtml.Append("<td  width='10%'> 建单时间：" + ((DateTime)dr["BuildTime"]).ToString("yyyy-MM-dd") + " \n 开始时间：" + ((DateTime)dr["StartTime"]).ToString("yyyy-MM-dd") + "\n 结束时间：" + (string.Format("{0:yyyy-MM-dd}", dr["EndTime"])) + "</td>");

            strHtml.Append("<td><input name='chk' type='checkbox' value='" + dr["BuyPlanGoodsId"].ToString() + "'></td>");

            strHtml.Append("</tr>");
        }
        strHtml.Append("</table>");
        Lablist.Text = strHtml.ToString();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        dr = null;
        db = null;
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键
    }

    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        // 07/09/11 马
       // string _strTemp = " BuyGoodsView.ProjectId=" + _strProjectId + " and GoodsNum=0 and BuyStatus=2 and",
        string _strTemp = "  GoodsNum=0 and BuyStatus=2 and",
            _strProductName, _strMedicinemodel, _strOutlookc, _strGoodsName, _GoodsId, _strCompanyNameSC, _UserCodeSC, _strHospital, _strHospitalcode;
        //采购单号
        string _strBuyPlanId = txtBuyPlanId.Text;
        if (_strBuyPlanId != "")
        {
            _strTemp += "  BuyPlanId=" + _strBuyPlanId + "  and";
        }
        //通用名
        _strProductName = txtProductName.Text.ToString().Trim();
        if (_strProductName != "")
        {
            _strTemp += "   ( ProductName like '%" + _strProductName + "%' or Product_SpellingCode like '%" + _strProductName + "%' )  and";
        }

        //剂型
        _strMedicinemodel = txtMedicinemodel.Text.ToString().Trim();
        if (_strMedicinemodel != "")
        {
            _strTemp += " medicinemodel like '%" + _strMedicinemodel + "%' and";
        }

        //规格
        _strOutlookc = txtOutlook.Text.ToString().Trim();
        if (_strOutlookc != "")
        {
            _strTemp += " outlookc like '%" + _strOutlookc + "%' and";
        }

        //商品名
        _strGoodsName = txtGoodsName.Text.ToString().Trim();
        if (_strGoodsName != "")
        {
            _strTemp += " goodsname like '%" + _strGoodsName + "%' and";
        }

        //商品流水号
        _GoodsId = txtGoodsId.Text.ToString().Trim();
        if (_GoodsId != "")
        {
            _strTemp += " GoodsId =" + _GoodsId + " and";
        }

        //生产企业名称
        _strCompanyNameSC = txtCompanyNameSC.Text.ToString().Trim();
        if (_strCompanyNameSC != "")
        {
            _strTemp += " CompanyName_SC like '%" + _strCompanyNameSC + "%' and";
        }

        //生产企业编码
        _UserCodeSC = txtUserCodeSC.Text.ToString().Trim();
        if (_UserCodeSC != "")
        {
            _strTemp += " UserCode_SC like '%" + _UserCodeSC + "%' and";
        }
        //医院名称
        _strHospital = TextHospital.Text.ToString().Trim();
        if (_strHospital != "")
        {
            _strTemp += " HospitalName like '%" + _strHospital + "%' and";
        }
        //医院注册号
        _strHospitalcode = TextHospitalcode.Text.ToString().Trim();
        if (_strHospitalcode != "")
        {
            _strTemp += " UserCode like '%" + _strHospitalcode + "%' and";
        }
        //配送状态
        //DealStatus When '0' Then '未确认' WHEN '1' Then '确认送货' WHEN '2' then '确认入库' WHEN '3' then '退货'
        //string _strDealStatus = listDealStatus.SelectedValue;
        //switch (_strDealStatus)
        //{
        //    case "全部":
        //        break;
        //    case "未确认送货":
        //        _strTemp += " DealStatus=0 and";
        //        break;
        //    case "已确认送货":
        //        _strTemp += " DealStatus<>0 and";
        //        break;
        //}

        if (_strTemp != "")
        {
            _strTemp = "  " + _strTemp.Substring(0, _strTemp.Length - 3);
        }

        return _strTemp;

    }
    #region TraDes 成员

    public string Name
    {
        get { return "采购数量为零记录"; }
    }

    public string Describe
    {
        get { return ""; }
    }

    public string ParentName
    {
        get { return "采购药品管理"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
            return _AccountType;
        }
    }

    #endregion
    
}
